package com.zhixiang.xaec.service.performance.safeachievements.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhixiang.core.dao.BaseDao;
import com.zhixiang.core.service.impl.BaseServiceImpl;
import com.zhixiang.xaec.dao.performance.safeachievements.InternalAssessDao;
import com.zhixiang.xaec.entity.performance.safeachievements.InternalAchiving;
import com.zhixiang.xaec.entity.performance.safeachievements.InternalAssess;
import com.zhixiang.xaec.entity.performance.safeachievements.RatingProjectSet;
import com.zhixiang.xaec.service.performance.safeachievements.InternalAchivingService;
import com.zhixiang.xaec.service.performance.safeachievements.InternalAssessService;
import com.zhixiang.xaec.service.performance.safeachievements.RatingProjectSetService;

@Service
public class InternalAssessServiceImpl extends BaseServiceImpl<InternalAssess, Long> implements 
InternalAssessService{

    @Autowired
    private InternalAchivingService internalAchivingService;
    
    @Autowired
    private RatingProjectSetService ratingProjectSetService;
    
    @Override
    @Resource(type=InternalAssessDao.class)
    public void setBaseDao(BaseDao<InternalAssess, Long> dao) {
        setDao(dao);
        
    }
    @Override
    public String delete(String[] ids) {
        for(String id:ids){
            getDao().remove(Long.valueOf(id));
        }
        return null;
    }
    
    @Override
    public InternalAssess save(InternalAssess internalAssess) {
            getDao().save(internalAssess);
            List<RatingProjectSet> ratingProjectSet=ratingProjectSetService.getAllByTreeId(internalAssess.getRatingProjectSetTreeId());
            for(int i=0;i<ratingProjectSet.size();i++){
                InternalAchiving internalAchiving=new InternalAchiving();
                internalAchiving.setOneLevel(ratingProjectSet.get(i).getOneLevel());
                internalAchiving.setTwoLevel(ratingProjectSet.get(i).getTwoLevel());
                internalAchiving.setRegulation(ratingProjectSet.get(i).getRegulation());
                internalAchiving.setStandardScore(ratingProjectSet.get(i).getStandardScore());
                internalAchiving.setBaseStandard(ratingProjectSet.get(i).getBaseStandard());
                internalAchiving.setInternalAssessId(internalAssess.getId());
                internalAchiving.setRatingProjectSetTreeId(internalAssess.getRatingProjectSetTreeId());
                internalAchivingService.save(internalAchiving);  
            }
            return null;
    }
}
